package com.ruoyi.courses.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.courses.domain.CourseNature;
import com.ruoyi.courses.service.ICourseNatureService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 课程性质Controller
 * 
 * @author ruoyi
 * @date 2024-11-22
 */
@RestController
@RequestMapping("/courseNature/courseNature")
public class CourseNatureController extends BaseController
{
    @Autowired
    private ICourseNatureService courseNatureService;

    /**
     * 查询课程性质列表
     */
    @PreAuthorize("@ss.hasPermi('courseNature:courseNature:list')")
    @GetMapping("/list")
    public TableDataInfo list(CourseNature courseNature)
    {
        startPage();
        List<CourseNature> list = courseNatureService.selectCourseNatureList(courseNature);
        return getDataTable(list);
    }

    /**
     * 导出课程性质列表
     */
    @PreAuthorize("@ss.hasPermi('courseNature:courseNature:export')")
    @Log(title = "课程性质", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CourseNature courseNature)
    {
        List<CourseNature> list = courseNatureService.selectCourseNatureList(courseNature);
        ExcelUtil<CourseNature> util = new ExcelUtil<CourseNature>(CourseNature.class);
        util.exportExcel(response, list, "课程性质数据");
    }

    /**
     * 获取课程性质详细信息
     */
    @PreAuthorize("@ss.hasPermi('courseNature:courseNature:query')")
    @GetMapping(value = "/{natureId}")
    public AjaxResult getInfo(@PathVariable("natureId") Long natureId)
    {
        return success(courseNatureService.selectCourseNatureByNatureId(natureId));
    }

    /**
     * 新增课程性质
     */
    @PreAuthorize("@ss.hasPermi('courseNature:courseNature:add')")
    @Log(title = "课程性质", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CourseNature courseNature)
    {
        return toAjax(courseNatureService.insertCourseNature(courseNature));
    }

    /**
     * 修改课程性质
     */
    @PreAuthorize("@ss.hasPermi('courseNature:courseNature:edit')")
    @Log(title = "课程性质", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CourseNature courseNature)
    {
        return toAjax(courseNatureService.updateCourseNature(courseNature));
    }

    /**
     * 删除课程性质
     */
    @PreAuthorize("@ss.hasPermi('courseNature:courseNature:remove')")
    @Log(title = "课程性质", businessType = BusinessType.DELETE)
	@DeleteMapping("/{natureIds}")
    public AjaxResult remove(@PathVariable Long[] natureIds)
    {
        return toAjax(courseNatureService.deleteCourseNatureByNatureIds(natureIds));
    }
}
